IF(NOT GETOPT_NAMESPACE)
  SET(GETOPT_NAMESPACE "GETOPT")
  SET(GETOPT_STANDALONE 1)
ENDIF(NOT GETOPT_NAMESPACE)
# In all cases:
STRING(TOLOWER ${GETOPT_NAMESPACE} GETOPT_LIBRARY_NAME)

PROJECT(${GETOPT_NAMESPACE} C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.2)

#SET(BUILD_SHARED_LIBS OFF)

SET(GETOPT_SRCS
  getopt.c
  getopt_long.c
  )
IF(WIN32)
  IF (BUILD_SHARED_LIBS)
    ADD_DEFINITIONS(-DGETOPT_DLL)
  ENDIF (BUILD_SHARED_LIBS)
ENDIF(WIN32)

#INCLUDE_DIRECTORIES(BEFORE
#  ${CMAKE_CURRENT_SOURCE_DIR}
#  )

# Only build this lib static. On most unix system
# we will be using the standart getopt
# so this lib will be for the poor Win32 user (those
# guys really need help)
ADD_LIBRARY(${GETOPT_LIBRARY_NAME} ${GETOPT_SRCS})
SET_TARGET_PROPERTIES(${GETOPT_LIBRARY_NAME} PROPERTIES ${GDCM_LIBRARY_PROPERTIES})

IF(BUILD_EXAMPLES)
ADD_EXECUTABLE(ex_getopt ex_getopt.c)
TARGET_LINK_LIBRARIES(ex_getopt ${GETOPT_LIBRARY_NAME})

IF(NOT GETOPT_INSTALL_NO_LIBRARIES)
  INSTALL(TARGETS ${GETOPT_LIBRARY_NAME} ex_getopt
    RUNTIME DESTINATION ${GETOPT_INSTALL_BIN_DIR} COMPONENT Runtime
    LIBRARY DESTINATION ${GETOPT_INSTALL_LIB_DIR} COMPONENT Runtime
    ARCHIVE DESTINATION ${GETOPT_INSTALL_LIB_DIR} COMPONENT Development
  ${CPACK_NAMELINK_TYPE}
  )
ENDIF(NOT GETOPT_INSTALL_NO_LIBRARIES)
ENDIF(BUILD_EXAMPLES)

